Fixes for subrip.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 9 Jun 2014 17:39:07 +0000 (17:39 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 9 Jun 2014 17:39:07 +0000 (17:39 +0000)
gpsbabel/reference/track/gpx_subsecond-sample~subrip.srt
gpsbabel/subrip.cc

index 2d69cc6ff850941247327b85b990fc08fddae7af..00803a8abf46c0e59b69bad44c0700cdace3d7a0 100644 (file)
@@ -1,20 +1,25 @@
 1
-17:47:25,200 --> 17:47:25,400 --> 49.7 km/h  289 m
+00:00:00,200 --> 00:00:00,400
+49.7 km/h  289 m
 17:47:25 Lat=49.79469 Lon=9.83402
 
 2
-17:47:25,400 --> 17:47:25,600 --> 50.6 km/h  289 m
+00:00:00,400 --> 00:00:00,600
+50.6 km/h  289 m
 17:47:25 Lat=49.79472 Lon=9.83400
 
 3
-17:47:25,600 --> 17:47:25,800 --> 51.0 km/h  289 m
+00:00:00,600 --> 00:00:00,800
+51.0 km/h  289 m
 17:47:25 Lat=49.79474 Lon=9.83398
 
 4
-17:47:25,800 --> 17:47:26,000 --> 50.7 km/h  289 m
+00:00:00,800 --> 00:00:01,000
+50.7 km/h  289 m
 17:47:25 Lat=49.79476 Lon=9.83396
 
 5
-17:47:26,000 --> 17:47:27,000 --> 51.1 km/h  289 m
+00:00:01,000 --> 00:00:02,000
+51.1 km/h  289 m
 17:47:26 Lat=49.79479 Lon=9.83394
 
index 2bf1b0862e4896ae4343fb00374afc835ecf9341..c42d0891d684147ed1eb6c5fcd54ca243adee1c7 100644 (file)
@@ -53,32 +53,12 @@ sync_time(time_t arg_gpstime, char* arg_videotime)
   return result;
 }
 
-static QDateTime
-gps_to_video_time(QDateTime arg_gpstime)
-{
-  QDateTime result = arg_gpstime;
-  /* Converts a GPS timestamp to relative time in the video stream. */
-  result.addSecs(time_offset);
-  return result;
-}
-
-// This appears to be only for subtitles so it's OK if we "wrap"
-// times across a midnight boundary.
-static void
-subrip_write_duration(QDateTime startdtime, QDateTime enddtime)
-{
-  QTime starttime = startdtime.time();
-  QTime endtime = enddtime.time();
-
-  /* Writes start and end time for subtitle display to file. */
-  gbfprintf(fout, "%02d:%02d:%02d,%03d --> ", starttime.hour(), starttime.minute(), starttime.second(), starttime.msec());
-
-  gbfprintf(fout, "%02d:%02d:%02d,%03d --> ", endtime.hour(), endtime.minute(), endtime.second(), endtime.msec());
-}
-
 static void
 subrip_prevwp_pr(const Waypoint* waypointp)
 {
+  QDateTime startdtime, enddtime;
+  QTime starttime, endtime;
+
   /* Now that we have the next waypoint, we can write out the subtitle for
    * the previous one.
    */
@@ -90,17 +70,20 @@ subrip_prevwp_pr(const Waypoint* waypointp)
     return;
   }
 
-  QDateTime starttime = gps_to_video_time(prevwpp->GetCreationTime());
-  QDateTime endtime;
+  gbfprintf(fout, "%d\n", stnum++);
 
+  /* Writes start and end time for subtitle display to file. */
+  startdtime = prevwpp->GetCreationTime().addSecs(-time_offset);
   if (!waypointp) {
-    endtime = starttime.addSecs(1);
+    enddtime = startdtime.addSecs(1);
   } else {
-    endtime = gps_to_video_time(waypointp->GetCreationTime());
+    enddtime = waypointp->GetCreationTime().addSecs(-time_offset);
   }
-  gbfprintf(fout, "%d\n", stnum);
-  stnum++;
-  subrip_write_duration(starttime, endtime);
+  starttime = startdtime.toUTC().time();
+  endtime = enddtime.toUTC().time();
+  gbfprintf(fout, "%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\n",
+    starttime.hour(), starttime.minute(), starttime.second(), starttime.msec(),
+    endtime.hour(), endtime.minute(), endtime.second(), endtime.msec());
 
   for (char* c = opt_format; *c != '\0' ; c++) {
     char fmt;
@@ -125,7 +108,7 @@ subrip_prevwp_pr(const Waypoint* waypointp)
         break;
       case 't':
         {
-          QTime t = prevwpp->GetCreationTime().time();
+          QTime t = prevwpp->GetCreationTime().toUTC().time();
           gbfprintf(fout, "%02d:%02d:%02d", t.hour(), t.minute(), t.second());
           break;
         }